package servlet.Visitor;

import domain.Info;
import domain.Visitors;
import service.person.PersonService;
import service.person.PersonServiceImpl;
import service.visitor.VisitorService;
import service.visitor.VisitorServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class Visitor extends HttpServlet {

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub

        if (request.getSession().getAttribute("userloginflag") == null) {
            request.getRequestDispatcher("/index.jsp").forward(request, response);
        } else {
            if (request.getParameter("visitors_id") == null || request.getParameter("visitors") == "") {
                request.getRequestDispatcher("/admin/error/error404.jsp").forward(request, response);
                return;
            } else {
                VisitorService visitorService =new VisitorServiceImpl();
                int visitors_id = Integer.parseInt(request.getParameter("visitors_id"));
                Visitors visitors = visitorService.seeInfo(visitors_id);
                request.setAttribute("visitor", visitors);
                request.getRequestDispatcher("/app/visitor/info.jsp").forward(request, response);
                return;
            }
        }
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        doGet(request, response);
    }
}